<link href="<?php echo site_url() ?>assets/css/nhatnv.css" media="all" rel="stylesheet" type="text/css" />
<link href="<?php echo site_url() ?>assets/chosen_v1.4.2/chosen.css" media="all" rel="stylesheet" type="text/css" />

<div id="sidetabs_body_container">
    <div id="table_area" style="">
        <div id="action_bar" class="action_bar">
            <div id="list_header">
                <h1 id="page_title" class="db place_hide">Thêm thiết bị</h1>

            </div>
        </div>
        <div id="detail_area">
            <div id="details_wrapper" class="hideport3">
                <div class="column-50 wiform">
                    <?php if (@$error || @$zero): ?>
                        <style>
                            .notice_explanation p{  margin: 0px;}
                            .notice_explanation{ min-height: 20px; height: auto !important;float: left;}
                        </style>
                        <div class="notice_explanation bad">
                            <?php if (@$error): ?>
                                <?php echo $error ?>
                            <?php endif; ?>
                        </div>

                    <?php else: ?>
                        <?php if (in_array(@$status, array('Thêm thành công.'))): ?>
                            <script>
                                alert('Cập nhật thành công');
                                window.location = '<?php echo site_url() . 'add-device.html' ?>';
                            </script>
                        <?php endif; ?>
                    <?php endif; ?>
                    <?php
                    $att = array('class' => 's3edit', 'enctype' => 'multipart/form-data');
                    echo form_open('', $att);
                    ?>

                    <p>
                        <label>Tên thiết bị <b style="color: red">(*)</b></label>
                        <span>
                            <input class="w99 <?php echo (form_error('namedevice') ? 'textInputError' : '') ?>" id="" name="namedevice" type="text" value="<?php echo set_value('namedevice') ?>">

                        </span>
                    </p>
                    <?php echo form_error('namedevice'); ?>
                    <p>
                        <label>Mac thiết bị <b style="color: red">(*)</b></label>
                        <span>
                            <input class="w99 <?php echo (form_error('mac') ? 'textInputError' : '') ?>" id="" name="mac" type="text" value="<?php echo set_value('mac') ?>">

                        </span>
                    </p>
                    <?php echo form_error('mac'); ?>
                    <p>
                        <label>Nasid thiết bị <b style="color: red">(*)</b></label>
                        <span>
                            <input class="w99 <?php echo (form_error('nasid') ? 'textInputError' : '') ?>" id="" name="nasid" type="text" value="<?php echo set_value('nasid') ?>">
                        </span>
                    </p>
                    <?php echo form_error('nasid'); ?>
                    <p>
                        <label>UAMSERVER <b style="color: red">(*)</b></label>
                        <span>
                            <input class="w99 <?php echo (form_error('HS_UAMFORMAT') ? 'textInputError' : '') ?>" id="" name="HS_UAMFORMAT" type="text" value="<?php echo set_value('HS_UAMFORMAT', 'http://wicity.vn/homepage/') ?>">
                        </span>
                    </p>
                    <?php echo form_error('HS_UAMFORMAT'); ?>
                    <p>
                        <label>UAMHOMEPAGE <b style="color: red">(*)</b></label>
                        <span>
                            <input class="w99 <?php echo (form_error('HS_UAMHOMEPAGE') ? 'textInputError' : '') ?>" id="" name="HS_UAMHOMEPAGE" type="text" value="<?php echo set_value('HS_UAMHOMEPAGE', 'http://wicity.vn/homepage/redirect/') ?>">
                        </span>
                    </p>
                    <?php echo form_error('HS_UAMHOMEPAGE'); ?>
                    <p>
                        <label style="    font-size: 11px;">DEFSESSIONTIMEOUT <b style="color: red">(*)</b></label>
                        <span>
                            <input class="w99 <?php echo (form_error('HS_DEFSESSIONTIMEOUT') ? 'textInputError' : '') ?>" id="" name="HS_DEFSESSIONTIMEOUT" type="text" value="<?php echo set_value('HS_DEFSESSIONTIMEOUT', 21600) ?>">
                        </span>
                    </p>
                    <?php echo form_error('DEFSESSIONTIMEOUT'); ?>
                    <p>
                        <label>DEFIDLETIMEOUT <b style="color: red">(*)</b></label>
                        <span>
                            <input class="w99 <?php echo (form_error('HS_DEFIDLETIMEOUT') ? 'textInputError' : '') ?>" id="" name="HS_DEFIDLETIMEOUT" type="text" value="<?php echo set_value('HS_DEFIDLETIMEOUT', 21600) ?>">
                        </span>
                    </p>
                    <?php echo form_error('HS_DEFIDLETIMEOUT'); ?>
                    <p>
                        <label>Version hotspot <b style="color: red">(*)</b></label>
                        <span>
                            <input class="w99 <?php echo (form_error('version') ? 'textInputError' : '') ?>" id="" name="version" type="text" value="<?php echo set_value('version', 1) ?>">
                        </span>
                    </p>
                    <?php echo form_error('version'); ?>
                    <p>
                        <label>Nhóm mạng <b style="color: red">(*)</b></label>
                        <span>
                            <?php echo $fview->selectOption($networkgroup, (set_value('network_group') ? set_value('network_group'): $dataedit->network_group), (form_error('network_group') ? 'textselectError' : ""), 'network_group', 'network_group', 0, 'style="width: 100%;"'); ?>
                        </span>
                    </p>
                    <?php echo form_error('network_group'); ?>
                    <p>
                        <label>Địa điểm <b style="color: red">(*)</b></label>
                        <span>
                            <?php echo $fview->selectOption($place, (set_value('place') ? set_value('place') : @$dataedit->id_address), 'chosen-select-width '.(form_error('place') ? 'textselectError' : ""), 'place', 'place', 0, 'tabindex="-1" style="display: none;" data-placeholder="Nhập địa điểm cần tìm" '); ?>
                        </span>
                    </p>
                    <?php echo form_error('place'); ?>
                    <p>
                        <label>
                            File cấu hình tùy chỉnh
                            <br/>( file.zip )
                        </label>
                        <span>
                            <input type="file" class="w99" name="fileconfig" />
                        </span>
                    </p>

                    <p>
                        <label>Ghi chú</label>
                        <span>
                            <textarea style="  width: 99%;" name="content" rows="3">Thêm mới thiết bị ngày <?php echo date('H:i:s d/m/Y') ?></textarea>
                        </span>
                    </p>
                    <p>
                        <label>Trạng thái</label>
                        <span>
                            <?php echo $fview->selectOption(array('1' => 'Hoạt động', '0' => 'Không hoạt động'), @$dataedit->active ? @$dataedit->active : $this->input->post('active'), 'form-control', 'active', 'active', 0, 'style="width: 100%;"'); ?>
                        </span>
                    </p>
                    <?php echo form_error('active'); ?>
                    <p>
                        <label>&nbsp;</label>
                        <span>
                            <input type="submit" value="Lưu lại">
                            <input type="reset" value="Làm lại">
                        </span>
                    </p>
                    </form>
                </div>
                <div class="column-50">
                    <div class="map" id="googleMap" style="margin: 0px 0px 0px 50px;height: 700px;">

                    </div>
                    <script src="http://maps.googleapis.com/maps/api/js"></script>
                    <script>
                                        var map;
                                        function initialize() {
                                            var mapProp = {
                                                center: new google.maps.LatLng(15.9030623, 105.8066791, 6),
                                                zoom: 5,
                                                mapTypeId: google.maps.MapTypeId.ROADMAP
                                            };
                                            map = new google.maps.Map(document.getElementById("googleMap"), mapProp);

                                        }
                                        google.maps.event.addDomListener(window, 'load', initialize);
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
<style>
    #pagination{
    }
    #pagination a{
        padding: 5px 10px;
        margin: 10px 2px;
        border: 1px solid #CCC;
        background: #6E6E6E;
        color: #FFF;
    }
    #pagination strong{
        padding: 5px 10px;
        margin: 10px 2px;
        border: 1px solid #CCC;
        background-color: #FFF;
    }
    .chosen-container-single, .chosen-single span{
        width: 100% !important

    }
    .show-error-select-chosen{
            border: 1px solid #DE0000 !important;
            color: #DE0000 !important;
        }

    .chosen-single span {
        float: left !important;
    }
    .row-error{
        margin: 0px;
        color: #DE0000;
    }
</style>
<script src="<?php echo site_url() ?>assets/chosen_v1.4.2/chosen.jquery.js" type="text/javascript"></script>

<script>
    function setLocation(lat, long, address)
    {
        var mapProp = {
            center: new google.maps.LatLng(lat, long),
            zoom: 15,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        map = new google.maps.Map(document.getElementById("googleMap"), mapProp);
        var myLatlng = new google.maps.LatLng(lat, long);
        var popup = new google.maps.InfoWindow({content: address});
        var marker = new google.maps.Marker({position: myLatlng, map: map, html: address, icon: '', animation: google.maps.Animation.DROP});

        google.maps.event.addListener(marker, 'mouseover', function (e) {
            popup.setContent(this.html);
            popup.open(map, this);
        });
        google.maps.event.addListener(marker, 'mouseout', function (e) {
            popup.setContent(this.html);
        });

    }
    $(document).ready(function ()
    {
        $('#place').on('change', function ()
        {
            var id_place = $(this).val();
            $.ajax({
                type: 'get',
                url: '<?php echo site_url('get-map'); ?>',
                data: ({id: id_place}),
                success: function (_data)
                {
                    var dc = jQuery.parseJSON(_data);
                    setLocation(dc.lat, dc.long, dc.address);
                }
            });
        });

        $("#province").on('change', function ()
        {
            var id_province = $(this).val();
            $("#district_select").html('<input type="text" value="Plz, waitting..." class="form-control" name="">');
            $.ajax({
                type: 'get',
                url: '<?php echo site_url('get-district'); ?>',
                data: ({id: id_province}),
                success: function (_data)
                {
                    $("#district_select").html(_data);
                }
            });
        });

        $('.del_item').click(function () {
            var r = confirm("Bạn có chắc chắn xóa thiết bị này không?");
            if (r == true) {
                window.location = '<?php echo site_url() . 'device?type=delete&id='; ?>' + this.id;
            } else {
                return false;
            }
        });
    });
    
      var config = {
      '.chosen-select': {},
      '.chosen-select-deselect': {allow_single_deselect: true},
      '.chosen-select-no-single': {disable_search_threshold: 10},
      '.chosen-select-no-results': {no_results_text: 'Oops, nothing found!'},
      '.chosen-select-width': {width: "95%"}
  }
  for (var selector in config) {
      $(selector).chosen(config[selector]);
  }
    
<?php if (form_error('place')): ?>
        $('.chosen-single').addClass('show-error-select-chosen');
<?php endif; ?>
                                          
$(".chosen-select-width").chosen().change(function() {
    $('.chosen-single').removeClass('show-error-select-chosen');
    //$('#' + $(this).val()).show();
});

$('#network_group').on('change', function()
{
   $(this).removeClass('textselectError');
});

$('.w99').on('change', function()
{
    $(this).removeClass('textInputError');
});
</script>

